﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XH.SmartParking.IService;

namespace XH.SmartParking.Service
{
    public class PayService : IPayService
    {
        private string baseUrl = "http://43.142.250.100:9001";
        public string CheckState(string orderId)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(baseUrl);
                HttpResponseMessage resp = httpClient.GetAsync($"/api/WxPay/?orderId={orderId}")
                     .GetAwaiter().GetResult();
                string data = resp.Content.ReadAsStringAsync().GetAwaiter().GetResult();

                return data;
            }
        }

        public string Pay(string orderId, long amount)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Clear();
                httpClient.DefaultRequestHeaders.Add("accept", "*/*");
                httpClient.BaseAddress = new Uri(baseUrl);
                HttpResponseMessage resp = httpClient.GetAsync($"api/WxPay/{orderId}/{amount}")
                //HttpResponseMessage resp = httpClient.GetAsync($"http://43.142.250.100:9001/api/WxPay/{orderId}/{amount}")
                     .GetAwaiter().GetResult();
                string data = resp.Content.ReadAsStringAsync().GetAwaiter().GetResult();

                return data;
            }

            // 1   ->  1.0
        }
    }
}
